package com.demo.webapp.ui.displayer;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.demo.webapp.ui.Component;
import com.demo.webapp.ui.displayer.Displayer;
import com.demo.webapp.ui.displayer.DisplayerMapping;

/**
 * 展现器的抽象实现
 * 提供默认展现属性设置
 * 
 * @author ryuu.kk
 */
public abstract class AbstractDisplayer<T extends Component> implements Displayer<T> {
	/** 日志 **/
    protected final transient Log log = LogFactory.getLog(getClass());
    /** 展示层模型名称 **/
    private String name;
    /** Jsp输出 **/
    private JspWriter out;
    /** 默认目标地址 **/
    private String target;
    /** 附加配置属性 **/
    private String config;
    /** 展示层数据Map **/
    protected DisplayerMapping mapping;

	@Override
	public void init(PageContext pageContext, DisplayerMapping mapping) {
        this.out = pageContext.getOut();
        this.mapping = mapping;
	}

	@Override
	public abstract void display(T model) throws JspException, IOException;
	
	@Override
	public abstract void end(PageContext pageContext) throws JspException;
	
	@Override
	public String getName() {
		return this.name;
	}
	
	@Override
	public void setConfig(String config) {
		this.config = config;
	}
	
	@Override
	public String getConfig() {
		return config;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	public void setTarget(String target) {
		this.target = target;
	}
	
	@Override
	public String getTarget() {
		return this.target;
	}
	
	public JspWriter getOut() {
		return out;
	}
}